﻿using mars_client.csharp;
using mars_client.csharp.cache;
using mars_client.csharp.enums;
using mars_client.csharp.model;
using mars_client.csharp.model.vo;
using mars_client.csharp.radar;
using mars_client.csharp.vo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace mars_client.gui.window
{
    /// <summary>
    /// CreateGroupWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CreateGroupWindow : Window
    {
        public CreateGroupWindow()
        {
            InitializeComponent();
            

            GuiCache.Instance.setGui("CreateGroupWindow",this);
            this.Closed += CreateGroupWindow_Closed;
        }

        private void CreateGroupWindow_Closed(object sender, EventArgs e)
        {
            GuiCache guic = GuiCache.Instance;
            guic.removeGui("CreateGroupWindow");
        }

        public void select(object sender, MouseButtonEventArgs e)
        {
            StackPanel sp = (StackPanel)sender;
            if(sp.Background == Brushes.White)
            {
                sp.Background = Brushes.LightGray;
            }else
            {
                sp.Background = Brushes.White;
            }
        }

        private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MessageCO messageCO = new MessageCO();
            messageCO.type = (int)RequestEnum.request.CreateGroup;

            GroupVO groupVO = new GroupVO();
            groupVO.groupName = groupName.Text;
            groupVO.groupIntro = groupIntro.Text;
            groupVO.userVOs = new List<UserVO>();
            foreach (StackPanel sp in usersWrapper.Children)
            {
                if(sp.Background == Brushes.LightGray)
                {
                    UserVO userVO = new UserVO();
                    userVO.id = long.Parse(sp.Uid.ToString());
                    groupVO.userVOs.Add(userVO);
                }
            }
            groupVO.userVOs.Add(UserCache.Instance.userVO);
            messageCO.content = groupVO;

            Radar.Instance.sendData(messageCO);
            // 禁用按钮
            ((TextBlock)sender).IsEnabled = false;
        }
    }
}
